package com.jiepos.mpos.biz.service.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;

import com.jiepos.mpos.biz.service.service.ServiceInfService;
import com.jiepos.mpos.common.entity.App_Service_InfEntity;
import com.jiepos.mpos.core.controller.BaseController;
import com.jiepos.mpos.core.entity.Pagination;

/**
 * 业务维护Controller
 * @author Zhao.Jinkui
 * @version 1.0
 * @ProjectName: mpos
 * @Package com.jiepos.mpos.biz.service.controller
 * @ClassName ServiceInfController
 * @history
 * @UpdateRemark []
 * @since 2017/9/24
 */
@Controller
@RequestMapping("serviceInf")
public class ServiceInfController extends BaseController {

    @Autowired
    private ServiceInfService serviceInfService;


    /**
     * 进入业务维护页面
     * @param request
     * @param response
     * @param pagination
     * @return
     */
    @RequestMapping("/getServiceInfList.do")
    public ModelAndView getServiceInfList(HttpServletRequest request, HttpServletResponse response,Pagination pagination){
        ModelAndView model = new ModelAndView("/module/service/serviceinf/serviceinf_list");
        return super.getDetail(request, response, model);
    }

    /**
     * 查询业务信息Json数据
     * @param pagination
     * @param appServiceInfEntity
     * @return
     */
    @RequestMapping("/getServiceInfListJson.do")
    public @ResponseBody Map getServiceInfListJson(Pagination pagination,App_Service_InfEntity appServiceInfEntity){
        return serviceInfService.findByCondition(pagination,appServiceInfEntity);
    }

    /**
     * 根据uuid加载业务信息详情页面
     * @param request
     * @param response
     * @param service_uuid
     * @return
     */
    @RequestMapping("getServiceInfDetail.do")
    public ModelAndView getServiceInfDetail(HttpServletRequest request, HttpServletResponse response,String service_uuid){
        ModelAndView model = new ModelAndView("/module/service/serviceinf/serviceinf_detail");
        App_Service_InfEntity entity = serviceInfService.findByUUID(service_uuid);
        model.addObject("serviceInfEntity",entity);
        return super.getDetail(request,response,model);
    }

    /**
     * 进入新增业务界面
     * @param request
     * @param response
     * @param pagination
     * @return
     */
    @RequestMapping("/getServiceInfAdd.do")
    public ModelAndView getServiceInfAdd(HttpServletRequest request, HttpServletResponse response,Pagination pagination){
        ModelAndView model = new ModelAndView("/module/service/serviceinf/serviceinf_detail");
        return super.getDetail(request, response, model);
    }

    /**
     * 保存业务信息
     * @param request
     * @param response
     * @param entity
     * @return
     */
    @RequestMapping("/saveServiceInf.do")
    public ModelAndView saveServiceInf(HttpServletRequest request,HttpServletResponse response,App_Service_InfEntity entity){
        serviceInfService.saveServiceInf(entity,super.getLoginUser(request, response));
        Map map=super.getLoginUser(request, response);
        return new ModelAndView(new RedirectView("getServiceInfList.do"), map);
    }

    /**
     * 检查业务编号，业务名称是否已存在
     * @param entity
     * @return 不存在返回success，存在返回error
     */
    @RequestMapping("checkService")
    public @ResponseBody String checkService(App_Service_InfEntity entity){
        return serviceInfService.checkService(entity);
    }

    /**
     * 启用/冻结 业务
     * @param request
     * @param response
     * @param service_st 要更新为的业务状态
     * @param service_uuids 哪些业务要更新
     * @return
     */
    @RequestMapping("/updateServiceSt.do")
    @ResponseBody
    public void updateServiceSt(HttpServletRequest request, HttpServletResponse response,String service_st, String service_uuids){
        serviceInfService.updateServiceSt(service_st,service_uuids, super.getLoginUser(request, response));
    }
    
    /**
     * 获取业务树
     * @return
     */
    @RequestMapping("/getServiceInfTree.do")
	@ResponseBody
	public List<Map<String, Object>> getServiceInfTree(){
		return serviceInfService.getServiceInfTree();
	}

}
